Temporal Trends in Philadelphia Mortality: The Impact of COVID-19, the Opioid Crisis, and Harm-Reduction Interventions, 2012–2024

BMIN5030 Final Project

Author

Michael McGarvey

1 Overview

This project investigates how Philadelphia’s mortality patterns have been shaped by two overlapping public health emergencies: the COVID-19 pandemic and the opioid crisis. Using cause-specific mortality data from 2012–2024, contextual metrics on COVID-19 pandemic onset, vaccination data, and the Introduction of fentanyl into the opioid supply and naloxone distribution, the study quantifies excess deaths. It evaluates the impact of these events and interventions across demographic groups.

Faculty guidance has further refined the project’s direction: Dr. Do emphasized the importance of hypothesis-driven analysis, encouraging the development and iterative refinement of testable questions, while Dr. Damrauer proposed framing the project as a natural experiment—examining not only the onset of the crises but also the timing and impact of key interventions such as vaccine rollout and Narcan availability. Their insights underscore the importance of modeling how mortality trends respond to policy shifts and to differences in resource distribution, particularly across age, race, and gender.

The full project, including code and documentation, is available in my https://github.com/mlmcgarv/Final-Project-BMIN.git

2 Introduction

Philadelphia has experienced significant shifts in mortality patterns over the past decade, shaped by two overlapping public health emergencies: the COVID-19 pandemic and the opioid crisis. Mortality rates and causes changed during the initial years of the pandemic after 2020 and shifted again following 2014, when the potent synthetic opioid, fentanyl, began appearing in drug samples and overdose victims. A question of this project is whether these shifts in mortality reflect or intensify pre-existing disparities across age, race, and gender.

In response, the city launched targeted interventions to reduce mortality and mitigate harm. These included widespread COVID-19 vaccination beginning in late 2020 and expanded naloxone (Narcan) distribution, marked by key milestones: citywide distribution to first responders and community organizations in 2017, the installation of free Narcan vending machines in 2022, and over-the-counter availability in 2023. This project seeks to quantify changes in cause-specific mortality rates from 2012 onward and assess the extent to which these interventions influenced excess deaths and effected desparities.

The complexity of this problem demands an interdisciplinary approach. Public health and epidemiology provide frameworks for understanding disease burden and intervention strategies, biostatistics and informatics supply the tools to analyze large-scale mortality datasets, and social science highlights how structural inequities shape vulnerability to both infectious disease and substance use.

Faculty guidance from the informatics department further refined the project’s direction. Dr. Do emphasized the importance of hypothesis-driven analysis, encouraging the development and iterative refinement of testable questions. In response, I created a set of hypotheses examining how mortality trends shifted with the onset of crises and the rollout of interventions. Dr. Damrauer reinforced this approach by proposing that the project be framed as a natural experiment—analyzing not only the onset of COVID-19 and the introduction of fentanyl, but also the timing and impact of vaccine availability and naloxone distribution. Their insights underscore the importance of modeling how mortality trends respond to policy shifts and to differences in resource distribution, particularly across age, race, and gender.

3 Methods

Data Sources This project draws on the Philadelphia Vital Statistics mortality database (2012–2024), which provides annual, aggregated mortality data for Philadelphia County. Each record summarizes deaths by cause, demographic group, and metric type. Key fields include year, sex, race/ethnicity, age categories, leading cause of death, and mortality metrics such as counts, age‑adjusted rates per 100,000, and life expectancy. Records flagged as unreliable (<20 deaths) were retained to preserve temporal trends, while suppressed values (<10 deaths) were excluded to ensure data quality.

To contextualize mortality patterns, additional datasets were merged with the Vital Statistics database. These included annual COVID‑19 vaccination coverage (2020–present), naloxone (Narcan) distribution milestones (2017 citywide rollout, 2022 vending machines, 2023 over‑the‑counter availability), and critical inflection points such as the emergence of fentanyl in the drug supply (2014) and the onset of the COVID‑19 pandemic (2020). These contextual variables provide anchors for evaluating how crises and interventions shaped mortality trajectories.

Load required R packages for data import, cleaning, and analysis

Data Cleaning and Structuring Data preparation involved several steps. Unused columns such as geography_namegeography, and estimate_type were removed to streamline the dataset. Suppressed values (metric_value == -99999 or quality_flag == “suppressed”) were excluded, while records flagged as “unreliable” were retained to preserve long‑term patterns. Demographic categories were standardized to ensure consistency across years. Finally, contextual datasets on vaccination coverage, naloxone milestones, fentanyl introduction, and pandemic onset were merged with mortality records to create a unified analytic dataset.

Analytical Approach The analysis proceeded in five stages. First, total mortality summaries were calculated for Philadelphia by year, with contextual overlays marking fentanyl introduction, pandemic onset, and intervention milestones. Second, cause‑of‑death analysis was conducted through interactive plots of the top 10 causes of death by year, accompanied by tables highlighting rank and percent contributions of COVID‑19 and drug overdose mortality. Third, interrupted time‑series (ITS) regression models were used to estimate level and slope changes associated with critical inflection points (2014 fentanyl emergence, 2020 pandemic onset) and intervention years (vaccination rollout, naloxone milestones). Fourth, demographic analysis explored disparities across sex, race/ethnicity, and age groups, using regression models (linear, Poisson, negative binomial) to quantify associations between mortality counts, demographic indicators, and interventions. Finally, hypothesis testing was performed to evaluate mortality trends, intervention impacts, and interactions, with full hypotheses documented to guide analysis and interpretation. Hypothesis testing was incorporated to evaluate mortality trends, intervention impacts, and equity‑related interactions, with pre‑specified hypotheses documented to guide analysis and interpretation.

Hypotheses

  • Mortality Trends Hypotheses: Overall mortality rates increased after the onset of COVID‑19 (2020); opioid‑related mortality rose sharply after fentanyl emergence (2014); COVID‑19 deaths disproportionately affected older age groups; opioid‑related deaths disproportionately affected males; Black and Hispanic populations experienced higher excess mortality during COVID‑19 than white populations.

  • Intervention Impact Hypotheses: COVID‑19 mortality declined following vaccination rollout (late 2020 onward); opioid mortality declined after Narcan distribution to first responders (2017); free Narcan vending machines (2022) reduced overdose deaths; over‑the‑counter Narcan (2023) contributed to declines across demographic groups.

  • Interaction Hypotheses: Effectiveness of vaccination varied by race, age, and gender; Narcan’s impact was greater in younger age groups; mortality disparities narrowed following interventions, suggesting improved equity.

Specific Aims The overarching aim of this study is to evaluate how overlapping public health crises and subsequent interventions shaped mortality in Philadelphia between 2012 and 2024. Specifically, the analysis seeks to characterize annual trends in leading causes of death, calculate mortality counts and age‑standardized rates for major causes such as heart disease, cancer, overdose, and COVID‑19, and estimate the impact of crises on mortality trajectories. Interrupted time‑series regression is used to assess deviations in mortality patterns following the emergence of fentanyl in 2014 and the onset of the COVID‑19 pandemic in 2020. A further aim is to evaluate the moderating effects of interventions, including vaccination uptake and naloxone distribution, to determine whether these efforts reduced excess deaths and narrowed disparities across demographic groups. By integrating contextual data with mortality records, the study aims to provide a comprehensive assessment of how crises and interventions jointly influenced mortality trends in Philadelphia.


Data Preparation and Integration

Loading Packages and Preparing Mortality Data: To begin the analysis, I loaded the required R packages that support data wrangling, visualization, and statistical modeling. The tidyverse suite provided core tools for data manipulation and plotting, while packages such as janitorstandardized column names, readr enabled efficient CSV import, and MASS supported negative binomial regression. Additional packages like ggrepel and RColorBrewer improved plot readability and accessibility, and knitr and gt were used to generate clean, publication‑ready tables.

After setting up the environment, we imported the raw mortality dataset (Vital_Mortality_Cty‑2.csv), standardized its column names, and removed metadata fields not needed for analysis. Suppressed values (e.g., metric_value == ‑99999 or flagged as “suppressed”) were excluded, while unreliable records were retained to preserve long‑term trends. To avoid conflicts between packages, we explicitly called dplyr::select when dropping unused columns. Finally, we validated the import by checking column names and inspecting the dataset structure. These steps ensured that the dataset was tidy, consistent, and ready for downstream filtering, merging with contextual datasets, and modeling.

# Load required packages
suppressPackageStartupMessages({

library(tidyverse)     # Core toolkit: dplyr for wrangling, ggplot2 for visualization
library(janitor)       # clean_names() for standardized, consistent column names
library(readr)         # Fast, consistent CSV import
library(broom)         # Tidies model outputs into data frames
library(ggrepel)       # Improves readability of plot labels
library(RColorBrewer)  # Accessible color palettes for plots
library(MASS)          # Provides glm.nb() for Negative Binomial regression
library(knitr)         # kable() for clean, simple tables in R Markdown/Quarto
library(gt)            # gt() for polished, publication-ready tables
library(stringr)       # str_detect() and other string functions for filtering predictors
library(ggplot2)       # Explicitly loaded for forest plots (part of tidyverse, noted here)
library(patchwork)     # Combines multiple ggplot2 plots into a single layout
library(scales)        # for comma formatting
library(plotly)        # Plotly enables interactive visualizations in R
})
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'readr' was built under R version 4.5.2
select <- dplyr::select

# Import mortality data, clean names, drop metadata that I will not use, and filter suppressed values
mortality <- read_csv("Vital_Mortality_Cty-2.csv", skip = 1, show_col_types = FALSE) %>%
  clean_names() %>%
  # Explicitly call dplyr::select to avoid masking errors from other packages
  dplyr::select(-geography_name, -geography, -estimate_type) %>%
  # Filter out suppressed or placeholder values
  filter(
    metric_value != -99999,
    is.na(quality_flag) | quality_flag != "suppressed"
  )

# Quick validation of column names and structure
names(mortality)
 [1] "objectid"            "year"                "sex"                
 [4] "race_ethnicity"      "age_category"        "leading_cause_death"
 [7] "metric_name"         "metric_value"        "rank"               
[10] "quality_flag"       
glimpse(mortality)
Rows: 38,581
Columns: 10
$ objectid            <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,…
$ year                <dbl> 2024, 2024, 2024, 2024, 2024, 2024, 2024, 2024, 20…
$ sex                 <chr> "All sexes", "All sexes", "All sexes", "All sexes"…
$ race_ethnicity      <chr> "All races/ethnicities", "All races/ethnicities", …
$ age_category        <chr> "All ages", "All ages", "All ages", "All ages", "A…
$ leading_cause_death <chr> "All alcohol-attributable causes", "All alcohol-at…
$ metric_name         <chr> "alcohol_attributable_deaths", "age_adjusted_alcoh…
$ metric_value        <dbl> 502.503966, 30.814007, 3.707148, 16.017177, 11.154…
$ rank                <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
$ quality_flag        <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…

Preparation of Contextual Datasets: In this step, two external contextual datasets—opioid interventions and COVID‑19 vaccination coverage—were prepared for integration with the mortality data. The primary goal was to standardize their schemas to ensure consistency across sources. For both datasets, the year column was converted to integer type to align with the mortality database and enable accurate joins. Because different versions of the source files stored notes under varying column names, a single, consistent notes column was enforced (opioid_notes for opioid interventions and vax_notes for vaccination coverage). This was achieved using rename_with() and matches() to harmonize column names in a compact, reproducible way. Safeguards were applied with coalesce() to guarantee that the notes column always exists, even if missing in the source file, thereby preventing downstream errors and maintaining transparency. These steps ensured that both contextual datasets were tidy, consistent, and ready to be merged with the cleaned mortality data for subsequent analyses.

# Contextual Datasets Incorporated

# ---- Opioid crisis interventions ----
opioid_interventions <- read_csv("intervention_data.csv", show_col_types = FALSE) %>%
  clean_names() %>%
  mutate(year = as.integer(year)) %>%   # ensure year is numeric for merging
  # Standardize notes column across versions
  rename_with(~ "opioid_notes", matches("opioid_crisis_notes_philadelphia|notes")) %>%
  mutate(opioid_notes = coalesce(opioid_notes, NA_character_))

# ---- COVID-19 vaccination coverage ----
covid_vax <- read_csv("covid_vaccine_data.csv", show_col_types = FALSE) %>%
  clean_names() %>%
  mutate(year = as.integer(year)) %>%   # ensure year is numeric for merging
  # Standardize notes column across versions
  rename_with(~ "vax_notes", matches("covid_vaccine_notes_philadelphia|notes")) %>%
  mutate(vax_notes = coalesce(vax_notes, NA_character_))

Merging Mortality Data with Contextual Datasets: After cleaning and preparing the individual datasets, the next step was to merge the mortality records with contextual information on opioid interventions and COVID‑19 vaccination coverage. Defensive checks were applied to confirm that the year column was present in each dataset before merging, ensuring that joins would execute correctly. Using left_join() by year preserved all mortality observations while adding corresponding intervention and vaccination data where available. To prevent ambiguity in cases where datasets contained overlapping column names, explicit suffixes were applied during the joins, making the resulting variables easier to interpret in downstream analyses. Finally, the unified dataset was inspected with glimpse() to validate that the merges executed correctly and that the structure aligned with expectations. These refinements ensured that the merged dataset was both comprehensive and reliable, providing a solid foundation for subsequent analyses of mortality trends in relation to crises and interventions.

# ---- Merge mortality data with opioid interventions by year ----

# Defensive check: ensure 'year' exists in both datasets
stopifnot("year" %in% names(mortality))
stopifnot("year" %in% names(opioid_interventions))

mortality_with_opioid <- mortality %>%
  left_join(opioid_interventions, by = "year", suffix = c("", "_opioid"))

# ---- Merge the result with COVID-19 vaccination coverage by year ----

# Defensive check: ensure 'year' exists in vaccination dataset
stopifnot("year" %in% names(covid_vax))

mortality_full <- mortality_with_opioid %>%
  left_join(covid_vax, by = "year", suffix = c("", "_vax"))

# Preview the unified dataset to confirm joins worked correctly
glimpse(mortality_full)
Rows: 38,581
Columns: 13
$ objectid                         <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12…
$ year                             <dbl> 2024, 2024, 2024, 2024, 2024, 2024, 2…
$ sex                              <chr> "All sexes", "All sexes", "All sexes"…
$ race_ethnicity                   <chr> "All races/ethnicities", "All races/e…
$ age_category                     <chr> "All ages", "All ages", "All ages", "…
$ leading_cause_death              <chr> "All alcohol-attributable causes", "A…
$ metric_name                      <chr> "alcohol_attributable_deaths", "age_a…
$ metric_value                     <dbl> 502.503966, 30.814007, 3.707148, 16.0…
$ rank                             <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
$ quality_flag                     <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
$ opioid_notes                     <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
$ covid_vaccine_doses_philadelphia <dbl> 120000, 120000, 120000, 120000, 12000…
$ vax_notes                        <chr> "Updated seasonal shots; declining de…

4 Results

4.1 Mortality Summaries

Annual Mortality Trends: Data Preparation and Visualization: To summarize overall mortality patterns, the unified dataset (mortality_full) was filtered to include only rows representing all causes of death across all sexes, races/ethnicities, and age groups. Restricting the metric to raw death counts ensured that each year was represented by a single, clean value reflecting total mortality in Philadelphia. The year column was standardized as an integer, and death counts were renamed as total_deaths. Only relevant columns were retained using dplyr::select() (explicitly called to avoid function conflicts), and duplicates were removed to guarantee one row per year. Finally, a line plot with points was generated to visualize trends in total deaths over time. To improve readability, large values on the y‑axis were formatted with commas, and a consistent plotting theme was applied to maintain clarity across figures. This visualization provides a clear descriptive overview of mortality patterns and establishes a foundation for subsequent regression modeling.

# Filter to the single "All causes" row per year
annual_totals <- mortality_full %>%
  filter(
    sex == "All sexes",                         
    race_ethnicity == "All races/ethnicities",  
    age_category == "All ages",                 
    leading_cause_death == "All causes",        
    metric_name == "count_of_deaths"            
  ) %>%
  mutate(year = as.integer(year)) %>%           
  dplyr::select(year, total_deaths = metric_value) %>%  
  distinct()                                    

# Plot total deaths per year with refinements
ggplot(annual_totals, aes(x = year, y = total_deaths)) +
  geom_line(color = "steelblue", size = 1.2) +
  geom_point(color = "darkred", size = 2) +
  labs(
    title = "Total Deaths per Year in Philadelphia",
    subtitle = "All causes, all ages, sexes, and races/ethnicities",
    x = "Year",
    y = "Total Deaths"
  ) +
  scale_y_continuous(labels = comma) +   # axis scaling for readability
  theme_classic(base_size = 14)          # consistent theme across plots
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.

Mortality Trends with Opiode Interventions and Vaccine Milestones: Building on the annual mortality totals, a line chart was created to display total deaths per year in Philadelphia. Points were added to highlight each year’s value, and vertical dashed lines were layered to mark major public health interventions. Opioid‑related events — including the fentanyl surge (2014), Narcan distribution (2017), vending machine rollout (2022), and OTC Narcan availability (2023) — were each assigned distinct colors to differentiate their timing and impact. In contrast, COVID‑related milestones were consistently marked in blue for visual coherence.

To enhance readability, the COVID onset year was labeled at the top of the plot, while vaccine rollout years were marked at the bottom with their actual dose counts. This design choice separates onset and rollout labels vertically, reducing clutter while still showing how both types of interventions align with mortality trends.

The resulting visualization provides a context‑rich overview that integrates mortality patterns with opioid and COVID responses, offering a clear depiction of how these public health milestones intersect with annual death counts in Philadelphia.

# Join vaccine dose counts into annual_totals
annual_totals_with_vax <- annual_totals %>%
  dplyr::left_join(
    covid_vax %>% dplyr::select(year, covid_vaccine_doses_philadelphia),
    by = "year"
  )

# Automatically detect the first year with vaccine doses (COVID onset year)
covid_onset_year <- annual_totals_with_vax %>%
  dplyr::filter(!is.na(covid_vaccine_doses_philadelphia)) %>%
  dplyr::summarise(first_year = min(year)) %>%
  dplyr::pull(first_year)

# Plot
ggplot(annual_totals_with_vax, aes(x = year, y = total_deaths)) +
  # Base mortality trend
  geom_line(color = "steelblue", size = 1.2) +
  geom_point(color = "darkred", size = 2) +
  
  # Opioid intervention milestones
  geom_vline(xintercept = 2014, linetype = "dashed", color = "red") +
  geom_vline(xintercept = 2017, linetype = "dashed", color = "purple") +
  geom_vline(xintercept = 2022, linetype = "dashed", color = "darkgreen") +
  geom_vline(xintercept = 2023, linetype = "dashed", color = "orange") +
  
  # COVID onset marker (auto-detected)
  geom_vline(xintercept = covid_onset_year, linetype = "dashed", color = "blue") +
  
  # Labels for interventions
  annotate("text", x = 2014, y = max(annual_totals_with_vax$total_deaths)*0.95,
           label = "Fentanyl surge", angle = 90, vjust = -0.5, color = "red") +
  annotate("text", x = 2017, y = max(annual_totals_with_vax$total_deaths)*0.95,
           label = "Narcan distribution", angle = 90, vjust = -0.5, color = "purple") +
  annotate("text", x = covid_onset_year, y = max(annual_totals_with_vax$total_deaths)*0.92,
           label = paste("COVID onset (", covid_onset_year, ")", sep = ""),
           angle = 90, vjust = -0.5, color = "blue") +
  annotate("text", x = 2022, y = max(annual_totals_with_vax$total_deaths)*0.95,
           label = "Narcan vending machines", angle = 90, vjust = -0.5, color = "darkgreen") +
  annotate("text", x = 2023, y = max(annual_totals_with_vax$total_deaths)*0.95,
           label = "OTC Narcan", angle = 90, vjust = -0.5, color = "orange") +
  
  # Vaccine dose labels
  geom_text(
    data = annual_totals_with_vax %>% dplyr::filter(!is.na(covid_vaccine_doses_philadelphia)),
    aes(
      x = year,
      y = min(annual_totals_with_vax$total_deaths) * 1.05,
      label = paste0("Vaccines: ", covid_vaccine_doses_philadelphia)
    ),
    angle = 90, vjust = 1, color = "blue", inherit.aes = FALSE
  ) +
  
  labs(
    title = "Total Deaths per Year in Philadelphia",
    subtitle = "All causes, all ages, sexes, and races/ethnicities\nIntervention milestones and vaccine dose counts marked",
    x = "Year",
    y = "Total Deaths"
  ) +
  theme_minimal()

4.2 Top 10 Causes of Death by Year

Interactive Top 10 Causes of Death by Year (Table, Bar Chart, and Rank Trends) This analysis generates both tabular summaries and interactive visualizations to track how leading causes of death evolve over time. Records are filtered to include all sexes, races/ethnicities, and ages while excluding the aggregate “All causes” category, with suppressed or invalid values removed to ensure data quality. Annual totals are computed to serve as denominators for percentage calculations, and each cause is ranked by death count within its year, with its share of total mortality expressed as a percentage. Only the top 10 causes per year are retained, producing a concise dataset. A formatted summary table lists year, rank, cause, deaths, and percent contribution, while a stacked bar chart highlights COVID‑19 (red), drug overdose (orange), and cancer (blue) against other causes, with hover tooltips revealing rank, deaths, and percent contribution. Complementing this, an interactive line chart shows how the rank of each cause shifts over time, with rank 1 (highest) displayed at the top of the y‑axis. Together, the table provides precise numeric detail, the bar chart shows absolute counts, and the line chart reveals relative importance. Interpretation highlights COVID‑19’s sharp rise and decline during the pandemic, drug overdose’s steady climb reflecting the opioid crisis, and cancer’s persistent burden. In short, this integrated approach combines numeric precision with dynamic visualization, offering a comprehensive view of how mortality drivers change year by year.

# Filter mortality dataset to include only valid records
leading_causes_table <- mortality_full %>%
  filter(sex == "All sexes",
         race_ethnicity == "All races/ethnicities",
         age_category == "All ages",
         metric_name == "count_of_deaths",
         leading_cause_death != "All causes",
         metric_value != -99999,
         (is.na(quality_flag) | quality_flag != "suppressed")) %>%
  mutate(year = as.integer(year)) %>%
  dplyr::select(year, leading_cause_death, deaths = metric_value)

# Compute totals per year
totals_per_year <- leading_causes_table %>%
  group_by(year) %>%
  summarise(total_deaths = sum(deaths), .groups = "drop")

# Add rank and percentage contribution
leading_causes_ranked <- leading_causes_table %>%
  group_by(year) %>%
  mutate(rank = dense_rank(desc(deaths))) %>%
  left_join(totals_per_year, by = "year") %>%
  mutate(percent = round(100 * deaths / total_deaths, 1)) %>%
  ungroup()

# Keep only top 10 causes per year
top10_table <- leading_causes_ranked %>%
  filter(rank <= 10) %>%
  arrange(year, rank)

# Print nicely formatted table
top10_table %>%
  dplyr::select(year, rank, leading_cause_death, deaths, percent)
# A tibble: 131 × 5
    year  rank leading_cause_death                deaths percent
   <int> <int> <chr>                               <dbl>   <dbl>
 1  2012     1 Heart disease                        3269    26.6
 2  2012     2 Cancer                               3252    26.5
 3  2012     3 Lung cancer                           889     7.2
 4  2012     4 Stroke                                681     5.5
 5  2012     5 Chronic lower respiratory diseases    641     5.2
 6  2012     6 Drug overdose (unintentional)         429     3.5
 7  2012     7 Diabetes                              352     2.9
 8  2012     8 Homicide                              323     2.6
 9  2012     9 Kidney disease                        318     2.6
10  2012    10 Sepsis                                312     2.5
# ℹ 121 more rows
# Reuse the ranked dataset from the table chunk
top10_causes <- leading_causes_ranked %>%
  filter(rank <= 10)

# Step 1: Build distinct color palette for all causes
all_causes <- unique(top10_causes$leading_cause_death)
palette <- scales::hue_pal()(length(all_causes))
names(palette) <- all_causes

# Step 2: Override specific colors to emphasize key causes
palette["COVID-19"] <- "firebrick"                       # strong red
palette["Drug overdose (unintentional)"] <- "darkorange" # bold orange
palette["Cancer"] <- "steelblue"                         # subtle cool blue

# Step 3: Build ggplot with hover text
p <- ggplot(top10_causes, aes(x = factor(year), y = deaths, fill = leading_cause_death,
                              text = paste0("Cause: ", leading_cause_death,
                                            "<br>Rank: ", rank,
                                            "<br>Deaths: ", deaths,
                                            "<br>Percent: ", percent, "%"))) +
  geom_bar(stat = "identity", width = 0.8) +   # narrower bars for spacing
  scale_fill_manual(values = palette) +
  labs(title = "Top 10 Causes of Death per Year",
       subtitle = "All sexes, all races/ethnicities, all ages (excluding All causes)",
       x = "Year", y = "Deaths") +
  theme_minimal() +
  theme(
    legend.position = "right",
    legend.title = element_blank(),
    axis.text.x = element_text(angle = 45, hjust = 1)   # rotate labels to avoid overlap
  )

# Step 4: Convert to interactive plotly chart with hover tooltips
ggplotly(p, tooltip = "text")
# Prepare the ranked dataset
leading_causes_table <- mortality_full %>%
  filter(sex == "All sexes",
         race_ethnicity == "All races/ethnicities",
         age_category == "All ages",
         metric_name == "count_of_deaths",
         leading_cause_death != "All causes",
         metric_value != -99999,
         (is.na(quality_flag) | quality_flag != "suppressed")) %>%
  mutate(year = as.integer(year)) %>%
  dplyr::select(year, leading_cause_death, deaths = metric_value)   # fix: force dplyr::select

# Compute totals per year
totals_per_year <- leading_causes_table %>%
  group_by(year) %>%
  summarise(total_deaths = sum(deaths), .groups = "drop")

# Add rank and percentage contribution
leading_causes_ranked <- leading_causes_table %>%
  group_by(year) %>%
  mutate(rank = dense_rank(desc(deaths))) %>%
  left_join(totals_per_year, by = "year") %>%
  mutate(percent = round(100 * deaths / total_deaths, 1)) %>%
  ungroup()

# Keep only top 10 causes per year
top10_causes <- leading_causes_ranked %>%
  filter(rank <= 10)

# Build full color palette for all causes
all_causes <- unique(top10_causes$leading_cause_death)
palette <- hue_pal()(length(all_causes))
names(palette) <- all_causes

# Override specific colors for emphasis
palette["COVID-19"] <- "firebrick"
palette["Drug overdose (unintentional)"] <- "darkorange"
palette["Cancer"] <- "steelblue"

# Interactive line chart with lines + markers
plot_ly(top10_causes,
        x = ~year,
        y = ~rank,
        color = ~leading_cause_death,
        colors = palette,
        type = 'scatter',
        mode = 'lines+markers',
        text = ~paste("Cause:", leading_cause_death,
                      "<br>Rank:", rank,
                      "<br>Deaths:", deaths,
                      "<br>Percent:", percent, "%"),
        hoverinfo = "text") %>%
  layout(title = "Interactive Rank Trends in Top 10 Causes of Death per Year",
         xaxis = list(title = "Year"),
         yaxis = list(title = "Rank (1 = highest)", autorange = "reversed"))

4.4 Statistical Modeling

Now that the data have been visually contextualized, the next step is to formally test demographic differences using regression models. To prepare the dataset, contextual columns are merged into mortality_summary, ensuring intervention information is integrated alongside demographic mortality data. The process begins by selecting only the core variables—year, sex, race/ethnicity, age category, and total deaths—before joining additional contextual fields from mortality_full, including opioid notes, vaccine dose counts, and vaccination notes, with one unique row per year.

Categorical variables such as sex, race/ethnicity, and age category are converted to factors so they can be properly handled in regression models. Baselines are explicitly set for interpretability: Male for sex, White (NH) for race/ethnicity, and 25–44 years for age category. Binary indicators are then created for key milestones, covering both opioid and COVID interventions.

This structure produces a clean dataset with demographic and contextual predictors, providing a solid foundation for regression analysis of group differences and intervention effects.

# Start from the original mortality_summary (demographics + deaths only)
mortality_summary <- mortality_summary %>%
  # Keep only the core demographic and death count columns
  dplyr::select(year, sex, race_ethnicity, age_category, total_deaths) %>%
  
  # Join in contextual variables cleanly from mortality_full
  left_join(
    mortality_full %>%
      dplyr::select(year, opioid_notes, covid_vaccine_doses_philadelphia, vax_notes) %>%
      group_by(year) %>%
      summarise(
        opioid_notes = first(opioid_notes),
        covid_vaccine_doses_philadelphia = first(covid_vaccine_doses_philadelphia),
        vax_notes = first(vax_notes),
        .groups = "drop"
      ),
    by = "year"
  ) %>%
  
  # Convert categorical variables to factors
  mutate(
    sex = factor(sex),
    race_ethnicity = factor(race_ethnicity),
    age_category = factor(age_category)
  ) %>%
  
  # Create binary indicators for interventions
  mutate(
    fentanyl_surge       = ifelse(year >= 2014, 1, 0),
    narcan_distribution  = ifelse(year >= 2017, 1, 0),
    narcan_vending_machines = ifelse(year >= 2022, 1, 0),
    otc_narcan           = ifelse(year >= 2023, 1, 0),
    covid_onset          = ifelse(year >= 2020, 1, 0),
    vaccine_rollout      = ifelse(!is.na(covid_vaccine_doses_philadelphia), 1, 0),
    booster_campaigns    = ifelse(year >= 2021, 1, 0)
  )

# Set baselines for categorical predictors
mortality_summary$sex <- relevel(mortality_summary$sex, ref = "Male")
mortality_summary$race_ethnicity <- relevel(mortality_summary$race_ethnicity, ref = "White (NH)")
mortality_summary$age_category <- relevel(mortality_summary$age_category, ref = "25-44")

Linear Regression (Exploratory), Interpreting Linear Regression of Mortality Counts with Demographics and Public Health Interventions: This exploratory linear regression examines associations between mortality counts, demographic factors, and public health interventions. Although linear regression is not ideal for count data, it provides a quick way to identify broad trends. The model explains about 63% of the variation in total deaths (R² = 0.635, Adjusted R² = 0.629), which is fairly strong for social and health data.

Demographic predictors are highly significant. Females show fewer deaths relative to males, most minority groups have lower mortality compared to White (NH), while Black (NH) shows a positive and significant association. Older age groups (45–64 and 65+) are linked to substantially higher death counts, while younger groups (5–14 and 15–24) show significant negative associations relative to the baseline 25–44 years.

The year variable has a very small, non‑significant coefficient, suggesting no linear trend once demographics are accounted for. Intervention indicators, coded as simple binary flags, show no significant effects in this framework, and vaccine rollout was dropped due to perfect collinearity with other predictors.

Overall, the results indicate that demographics drive most of the variation in mortality counts, while intervention indicators are not well captured in this linear setup. These findings underscore the limitations of linear regression for count data and motivate the use of more appropriate modeling strategies.

# Fit a linear regression model
# Purpose: Exploratory look at associations between demographics, interventions, and mortality counts
model <- lm(
  total_deaths ~ sex + race_ethnicity + age_category + year +
    fentanyl_surge + narcan_distribution + narcan_vending_machines + otc_narcan +
    covid_onset + vaccine_rollout + booster_campaigns,
  data = mortality_summary %>%
    mutate(
      sex = factor(sex),
      race_ethnicity = factor(race_ethnicity),
      age_category = factor(age_category)
    )
)

# Summarize the model output
summary(model)

Call:
lm(formula = total_deaths ~ sex + race_ethnicity + age_category + 
    year + fentanyl_surge + narcan_distribution + narcan_vending_machines + 
    otc_narcan + covid_onset + vaccine_rollout + booster_campaigns, 
    data = mortality_summary %>% mutate(sex = factor(sex), race_ethnicity = factor(race_ethnicity), 
        age_category = factor(age_category)))

Residuals:
    Min      1Q  Median      3Q     Max 
-4959.8 -1729.4  -450.2  1274.4 21193.1 

Coefficients: (1 not defined because of singularities)
                                     Estimate Std. Error t value Pr(>|t|)    
(Intercept)                          31419.25  259005.43   0.121   0.9035    
sexAll sexes                          1777.28     192.30   9.242  < 2e-16 ***
sexFemale                             -399.69     199.88  -2.000   0.0458 *  
race_ethnicityAll races/ethnicities   3456.84     255.36  13.537  < 2e-16 ***
race_ethnicityAsian/PI (NH)          -3899.85     296.24 -13.165  < 2e-16 ***
race_ethnicityBlack (NH)               552.98     255.46   2.165   0.0306 *  
race_ethnicityHispanic               -2462.34     265.43  -9.277  < 2e-16 ***
race_ethnicityMultiracial (NH)       -6036.79     367.46 -16.428  < 2e-16 ***
age_category0-4                      -1433.82     311.42  -4.604 4.59e-06 ***
age_category15-24                    -1407.85     309.97  -4.542 6.14e-06 ***
age_category45-64                     1485.72     279.57   5.314 1.28e-07 ***
age_category5-14                     -3259.63     409.36  -7.963 3.92e-15 ***
age_category65                        4492.10     276.33  16.256  < 2e-16 ***
age_categoryAll ages                  6600.16     275.95  23.918  < 2e-16 ***
year                                   -15.46     128.70  -0.120   0.9044    
fentanyl_surge                          62.13     415.01   0.150   0.8810    
narcan_distribution                     80.69     451.47   0.179   0.8582    
narcan_vending_machines               -258.38     424.16  -0.609   0.5425    
otc_narcan                            -321.39     404.31  -0.795   0.4268    
covid_onset                            635.73     423.10   1.503   0.1332    
vaccine_rollout                            NA         NA      NA       NA    
booster_campaigns                     -115.16     425.15  -0.271   0.7865    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2775 on 1186 degrees of freedom
Multiple R-squared:  0.6353,    Adjusted R-squared:  0.6292 
F-statistic: 103.3 on 20 and 1186 DF,  p-value: < 2.2e-16

Interpreting Poisson Regression of Mortality Counts with Demographics and Public Health Interventions: Extracting rate ratios from a Poisson regression in R allows results to be presented in a clear and interpretable format. The coefficients produced by the model are on the log scale, which can be difficult to interpret directly. By exponentiating these values, they are converted into rate ratios that represent multiplicative effects relative to the chosen baselines. In this analysis, Male is the baseline for sex, White (NH) for race/ethnicity, and 25–44 years for age category. Rate ratios greater than 1 indicate higher expected deaths relative to the baseline, while values less than 1 indicate lower expected deaths.

Demographic predictors show strong and highly significant associations. Females and most minority groups have lower expected deaths compared to baselines, while Black (NH) shows significantly higher mortality. Older age groups (45–64 and 65+) are associated with substantially higher deaths, and the “all ages” group shows the largest increase. Younger groups (0–4, 5–14, 15–24) display strong protective effects. The year variable indicates a small but statistically significant decline of about 0.6% fewer deaths per year.

Intervention indicators show mixed results. Opioid interventions are linked to small changes, with early milestones associated with slight increases and later measures (vending machines, OTC Narcan) with modest reductions. COVID onset corresponds to a substantial increase in deaths, while booster campaigns are associated with a modest decline. Vaccine rollout was dropped due to collinearity with other COVID variables.

Overall, the Poisson regression highlights the dominant role of demographics in explaining mortality variation, while interventions show measurable but smaller associations. Presenting the results in a tidy table improves readability and makes the findings easier to communicate.

# Fit a Poisson regression model
glm_model <- glm(
  total_deaths ~ sex + race_ethnicity + age_category + year +
    fentanyl_surge + narcan_distribution + narcan_vending_machines + otc_narcan +
    covid_onset + vaccine_rollout + booster_campaigns,
  family = poisson(link = "log"),
  data = mortality_summary %>%
    mutate(
      sex = factor(sex),
      race_ethnicity = factor(race_ethnicity),
      age_category = factor(age_category)
    )
)

# Summarize the model output
summary(glm_model)

Call:
glm(formula = total_deaths ~ sex + race_ethnicity + age_category + 
    year + fentanyl_surge + narcan_distribution + narcan_vending_machines + 
    otc_narcan + covid_onset + vaccine_rollout + booster_campaigns, 
    family = poisson(link = "log"), data = mortality_summary %>% 
        mutate(sex = factor(sex), race_ethnicity = factor(race_ethnicity), 
            age_category = factor(age_category)))

Coefficients: (1 not defined because of singularities)
                                      Estimate Std. Error  z value Pr(>|z|)    
(Intercept)                         18.1407520  1.9606328    9.252  < 2e-16 ***
sexAll sexes                         0.6610118  0.0014374  459.852  < 2e-16 ***
sexFemale                           -0.0640294  0.0016785  -38.146  < 2e-16 ***
race_ethnicityAll races/ethnicities  0.8721636  0.0015368  567.520  < 2e-16 ***
race_ethnicityAsian/PI (NH)         -2.8779035  0.0056331 -510.890  < 2e-16 ***
race_ethnicityBlack (NH)             0.1244576  0.0017706   70.291  < 2e-16 ***
race_ethnicityHispanic              -1.9202239  0.0036121 -531.613  < 2e-16 ***
race_ethnicityMultiracial (NH)      -5.2821156  0.0198421 -266.208  < 2e-16 ***
age_category0-4                     -1.9613309  0.0090986 -215.564  < 2e-16 ***
age_category15-24                   -1.6383122  0.0078745 -208.054  < 2e-16 ***
age_category45-64                    1.2044963  0.0035698  337.410  < 2e-16 ***
age_category5-14                    -4.0242473  0.0284256 -141.571  < 2e-16 ***
age_category65                       2.2199725  0.0032972  673.299  < 2e-16 ***
age_categoryAll ages                 2.6351028  0.0032419  812.817  < 2e-16 ***
year                                -0.0060280  0.0009742   -6.188 6.11e-10 ***
fentanyl_surge                       0.0282889  0.0031481    8.986  < 2e-16 ***
narcan_distribution                  0.0312274  0.0034188    9.134  < 2e-16 ***
narcan_vending_machines             -0.0518859  0.0030576  -16.969  < 2e-16 ***
otc_narcan                          -0.1145632  0.0029831  -38.404  < 2e-16 ***
covid_onset                          0.2514339  0.0030112   83.499  < 2e-16 ***
vaccine_rollout                             NA         NA       NA       NA    
booster_campaigns                   -0.0935821  0.0029528  -31.693  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 6699875  on 1206  degrees of freedom
Residual deviance:   68632  on 1186  degrees of freedom
AIC: 77944

Number of Fisher Scoring iterations: 5
# Exponentiated coefficients for easier interpretation
exp(coef(glm_model))
                        (Intercept)                        sexAll sexes 
                       7.558376e+07                        1.936751e+00 
                          sexFemale race_ethnicityAll races/ethnicities 
                       9.379774e-01                        2.392081e+00 
        race_ethnicityAsian/PI (NH)            race_ethnicityBlack (NH) 
                       5.625257e-02                        1.132534e+00 
             race_ethnicityHispanic      race_ethnicityMultiracial (NH) 
                       1.465741e-01                        5.081669e-03 
                    age_category0-4                   age_category15-24 
                       1.406711e-01                        1.943077e-01 
                  age_category45-64                    age_category5-14 
                       3.335079e+00                        1.787687e-02 
                     age_category65                age_categoryAll ages 
                       9.207078e+00                        1.394475e+01 
                               year                      fentanyl_surge 
                       9.939901e-01                        1.028693e+00 
                narcan_distribution             narcan_vending_machines 
                       1.031720e+00                        9.494372e-01 
                         otc_narcan                         covid_onset 
                       8.917556e-01                        1.285868e+00 
                    vaccine_rollout                   booster_campaigns 
                                 NA                        9.106633e-01 

Poisson regression coefficients are produced on the log scale, which can be difficult to interpret directly. By exponentiating these values, they are converted into rate ratios that represent multiplicative effects relative to chosen baselines: Male for sex, White (NH) for race/ethnicity, and 25–44 years for age category. Confidence intervals are included to show statistical precision and whether predictors differ significantly from 1, which represents no effect.

Demographic predictors show strong and highly significant associations. Females and most minority groups have lower expected deaths compared to baselines, while Black (NH) shows significantly higher mortality. Older age groups (45–64, 65+) are associated with substantially higher deaths, and younger groups (0–24) display strong protective effects. The year variable indicates a small but statistically significant decline of about 0.6% fewer deaths per year.

Intervention indicators show mixed results. Opioid milestones correspond to small changes, while COVID onset produced a large increase in deaths and booster campaigns modest reductions. Vaccine rollout was dropped due to collinearity with other COVID variables.

Overall, exponentiating coefficients into rate ratios provides interpretable measures that highlight the dominant role of demographics and the smaller, mixed effects of interventions on mortality counts.

# Extract tidy results with exponentiated coefficients and confidence intervals
exp_table <- tidy(glm_model, exponentiate = TRUE, conf.int = TRUE)

# Convert to tibble for clear variable names
exp_table <- as_tibble(exp_table)

# Format the table for polished readability
kable(exp_table, digits = 3, caption = "Rate Ratios from Poisson Regression with 95% Confidence Intervals")
Rate Ratios from Poisson Regression with 95% Confidence Intervals
term estimate std.error statistic p.value conf.low conf.high
(Intercept) 75583763.495 1.961 9.252 0 1620083.420 3.526348e+09
sexAll sexes 1.937 0.001 459.852 0 1.931 1.942000e+00
sexFemale 0.938 0.002 -38.146 0 0.935 9.410000e-01
race_ethnicityAll races/ethnicities 2.392 0.002 567.520 0 2.385 2.399000e+00
race_ethnicityAsian/PI (NH) 0.056 0.006 -510.890 0 0.056 5.700000e-02
race_ethnicityBlack (NH) 1.133 0.002 70.291 0 1.129 1.136000e+00
race_ethnicityHispanic 0.147 0.004 -531.613 0 0.146 1.480000e-01
race_ethnicityMultiracial (NH) 0.005 0.020 -266.208 0 0.005 5.000000e-03
age_category0-4 0.141 0.009 -215.564 0 0.138 1.430000e-01
age_category15-24 0.194 0.008 -208.054 0 0.191 1.970000e-01
age_category45-64 3.335 0.004 337.410 0 3.312 3.359000e+00
age_category5-14 0.018 0.028 -141.571 0 0.017 1.900000e-02
age_category65 9.207 0.003 673.299 0 9.148 9.267000e+00
age_categoryAll ages 13.945 0.003 812.817 0 13.857 1.403400e+01
year 0.994 0.001 -6.188 0 0.992 9.960000e-01
fentanyl_surge 1.029 0.003 8.986 0 1.022 1.035000e+00
narcan_distribution 1.032 0.003 9.134 0 1.025 1.039000e+00
narcan_vending_machines 0.949 0.003 -16.969 0 0.944 9.550000e-01
otc_narcan 0.892 0.003 -38.404 0 0.887 8.970000e-01
covid_onset 1.286 0.003 83.499 0 1.278 1.293000e+00
vaccine_rollout NA NA NA NA NA NA
booster_campaigns 0.911 0.003 -31.693 0 0.905 9.160000e-01

Rate Ratios from Poisson Regression of Mortality Counts: Rate ratios from the Poisson regression provide an accessible way to interpret the effects of demographics and interventions. A rate ratio represents the multiplicative effect on expected deaths, with values greater than 1 indicating higher expected deaths and values less than 1 indicating lower expected deaths relative to the baseline. Confidence intervals provide the 95% bounds for these estimates, while p‑values indicate statistical significance. In this analysis, Male is the baseline for sex, White (NH) for race/ethnicity, and 25–44 years for age category.

Demographic predictors show strong and highly significant associations. Females and most minority groups have lower expected deaths compared to baselines, while Black (NH) shows higher mortality. Age is a dominant factor: older groups (45–64, 65+) are associated with substantially higher deaths, while younger groups (0–24) display strong protective effects. The year variable indicates a small but statistically significant decline of about 0.6% fewer expected deaths per year.

Intervention effects are mixed. Opioid milestones correspond to small changes, while COVID onset produced a large increase in deaths and booster campaigns modest reductions. Vaccine rollout was dropped due to collinearity with other COVID variables.

Overall, demographics dominate mortality variation, while interventions show measurable but smaller associations. Presenting results in a structured table with confidence intervals and significance flags makes them easier to interpret and communicate.

# Tidy the Poisson regression output with exponentiated coefficients and confidence intervals
tidy_poisson <- broom::tidy(glm_model, conf.int = TRUE, exponentiate = TRUE)

# Format the table with clear variable names
rate_ratio_table <- tidy_poisson %>%
  dplyr::select(term, estimate, conf.low, conf.high, p.value) %>%
  dplyr::rename(
    Predictor = term,
    RateRatio = estimate,
    LowerCI   = conf.low,
    UpperCI   = conf.high,
    PValue    = p.value
  ) %>%
  dplyr::mutate(
    RateRatio = round(RateRatio, 3),
    LowerCI   = round(LowerCI, 3),
    UpperCI   = round(UpperCI, 3),
    PValue    = signif(PValue, 3),
    Significance = ifelse(PValue < 0.05, "Yes", "No"),
    Group = case_when(
      grepl("sex", Predictor) ~ "Demographics",
      grepl("race_ethnicity", Predictor) ~ "Demographics",
      grepl("age_category", Predictor) ~ "Demographics",
      Predictor == "year" ~ "Year Trend",
      Predictor %in% c("fentanyl_surge", "narcan_distribution", "narcan_vending_machines", "otc_narcan") ~ "Opioid Interventions",
      Predictor %in% c("covid_onset", "vaccine_rollout", "booster_campaigns") ~ "COVID Interventions",
      TRUE ~ "Other"
    )
  ) %>%
  dplyr::arrange(Group)

# Step 3: Print the polished table
knitr::kable(rate_ratio_table, digits = 3, caption = "Rate Ratios from Poisson Regression with 95% Confidence Intervals")
Rate Ratios from Poisson Regression with 95% Confidence Intervals
Predictor RateRatio LowerCI UpperCI PValue Significance Group
covid_onset 1.286 1.278 1.293000e+00 0 Yes COVID Interventions
vaccine_rollout NA NA NA NA NA COVID Interventions
booster_campaigns 0.911 0.905 9.160000e-01 0 Yes COVID Interventions
sexAll sexes 1.937 1.931 1.942000e+00 0 Yes Demographics
sexFemale 0.938 0.935 9.410000e-01 0 Yes Demographics
race_ethnicityAll races/ethnicities 2.392 2.385 2.399000e+00 0 Yes Demographics
race_ethnicityAsian/PI (NH) 0.056 0.056 5.700000e-02 0 Yes Demographics
race_ethnicityBlack (NH) 1.133 1.129 1.136000e+00 0 Yes Demographics
race_ethnicityHispanic 0.147 0.146 1.480000e-01 0 Yes Demographics
race_ethnicityMultiracial (NH) 0.005 0.005 5.000000e-03 0 Yes Demographics
age_category0-4 0.141 0.138 1.430000e-01 0 Yes Demographics
age_category15-24 0.194 0.191 1.970000e-01 0 Yes Demographics
age_category45-64 3.335 3.312 3.359000e+00 0 Yes Demographics
age_category5-14 0.018 0.017 1.900000e-02 0 Yes Demographics
age_category65 9.207 9.148 9.267000e+00 0 Yes Demographics
age_categoryAll ages 13.945 13.857 1.403400e+01 0 Yes Demographics
fentanyl_surge 1.029 1.022 1.035000e+00 0 Yes Opioid Interventions
narcan_distribution 1.032 1.025 1.039000e+00 0 Yes Opioid Interventions
narcan_vending_machines 0.949 0.944 9.550000e-01 0 Yes Opioid Interventions
otc_narcan 0.892 0.887 8.970000e-01 0 Yes Opioid Interventions
(Intercept) 75583763.495 1620083.420 3.526348e+09 0 Yes Other
year 0.994 0.992 9.960000e-01 0 Yes Year Trend

Interpreting Negative Binomial Regression of Mortality Counts with Demographics and Public Health Interventions: Negative binomial regression is a generalized linear model designed for count data when the variance exceeds the mean, a condition known as overdispersion. Unlike Poisson regression, which assumes the mean and variance are equal, the negative binomial model introduces a dispersion parameter (theta) that adjusts for extra variability, making it more robust for real‑world data such as mortality counts. Coefficients are expressed on the log scale, and exponentiating them yields rate ratios that represent multiplicative effects on expected deaths. Confidence intervals provide bounds for these estimates, while the dispersion parameter confirms whether overdispersion is present.

The model fit is strong: theta = 5.83 (SE = 0.25), residual deviance = 1,263.7 on 1,186 degrees of freedom, and AIC = 15,629. These values indicate better performance than the Poisson regression and validate the choice of negative binomial for this dataset.

Demographic predictors dominate. Females and most minority groups show significantly fewer expected deaths compared to baselines, while Black (NH) shows higher mortality. Age is a major factor: older groups (45–64, 65+) are associated with substantially higher deaths, while younger groups (5–24) display strong protective effects. The year variable is not significant, suggesting no clear linear trend once demographics are controlled.

Intervention indicators show mixed results. Opioid milestones such as the fentanyl surge and Narcan distribution are not significant, vending machines show a borderline reduction, and OTC Narcan demonstrates a clear protective effect (~16% fewer deaths). COVID onset corresponds to a strong increase (~25% higher deaths), while booster campaigns are not significant. Vaccine rollout was dropped due to collinearity with other COVID variables.

In sum, the negative binomial regression confirms that demographics are the primary drivers of mortality counts, while OTC Narcan and COVID onset show clear, significant effects. Given its strengths over Poisson, negative binomial regression will be used for the remainder of the analysis.

# Fit the negative binomial regression
# glm.nb adds a dispersion parameter to account for overdispersion in count data
nb_model <- MASS::glm.nb(
  total_deaths ~ sex + race_ethnicity + age_category + year +
    fentanyl_surge + narcan_distribution + narcan_vending_machines + otc_narcan +
    covid_onset + vaccine_rollout + booster_campaigns,
  data = mortality_summary %>%
    mutate(
      sex = factor(sex),
      race_ethnicity = factor(race_ethnicity),
      age_category = factor(age_category)
    )
)

# View model summary
summary(nb_model)

Call:
MASS::glm.nb(formula = total_deaths ~ sex + race_ethnicity + 
    age_category + year + fentanyl_surge + narcan_distribution + 
    narcan_vending_machines + otc_narcan + covid_onset + vaccine_rollout + 
    booster_campaigns, data = mortality_summary %>% mutate(sex = factor(sex), 
    race_ethnicity = factor(race_ethnicity), age_category = factor(age_category)), 
    init.theta = 5.826945797, link = log)

Coefficients: (1 not defined because of singularities)
                                     Estimate Std. Error z value Pr(>|z|)    
(Intercept)                          3.284304  39.966837   0.082 0.934507    
sexAll sexes                         0.520940   0.029619  17.588  < 2e-16 ***
sexFemale                           -0.450041   0.030888 -14.570  < 2e-16 ***
race_ethnicityAll races/ethnicities  1.167404   0.038715  30.154  < 2e-16 ***
race_ethnicityAsian/PI (NH)         -2.689073   0.045601 -58.969  < 2e-16 ***
race_ethnicityBlack (NH)             0.528334   0.038807  13.614  < 2e-16 ***
race_ethnicityHispanic              -1.266530   0.040818 -31.029  < 2e-16 ***
race_ethnicityMultiracial (NH)      -4.989162   0.059604 -83.705  < 2e-16 ***
age_category0-4                     -1.966104   0.048550 -40.497  < 2e-16 ***
age_category15-24                   -1.692627   0.047975 -35.281  < 2e-16 ***
age_category45-64                    1.133390   0.042689  26.550  < 2e-16 ***
age_category5-14                    -4.067976   0.068555 -59.339  < 2e-16 ***
age_category65                       2.209602   0.042134  52.442  < 2e-16 ***
age_categoryAll ages                 2.646069   0.042065  62.904  < 2e-16 ***
year                                 0.001296   0.019859   0.065 0.947974    
fentanyl_surge                      -0.011471   0.064053  -0.179 0.857875    
narcan_distribution                  0.028525   0.069683   0.409 0.682279    
narcan_vending_machines             -0.090833   0.065434  -1.388 0.165083    
otc_narcan                          -0.173794   0.062245  -2.792 0.005237 ** 
covid_onset                          0.222830   0.065047   3.426 0.000613 ***
vaccine_rollout                            NA         NA      NA       NA    
booster_campaigns                    0.017979   0.065471   0.275 0.783617    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for Negative Binomial(5.8269) family taken to be 1)

    Null deviance: 26495.4  on 1206  degrees of freedom
Residual deviance:  1263.7  on 1186  degrees of freedom
AIC: 15629

Number of Fisher Scoring iterations: 1

              Theta:  5.827 
          Std. Err.:  0.251 

 2 x log-likelihood:  -15585.079 
# Exponentiate coefficients to get rate ratios with confidence intervals
exp_table_nb <- cbind(
  Estimate   = coef(nb_model),                      # log-scale coefficients
  RateRatio  = exp(coef(nb_model)),                 # exponentiated coefficients
  LowerCI    = exp(confint(nb_model)[,1]),          # lower bound of CI
  UpperCI    = exp(confint(nb_model)[,2])           # upper bound of CI
)
Waiting for profiling to be done...
Waiting for profiling to be done...
# Print clean table
round(exp_table_nb, 3)
                                    Estimate RateRatio LowerCI      UpperCI
(Intercept)                            3.284    26.690   0.000 3.739765e+35
sexAll sexes                           0.521     1.684   1.588 1.785000e+00
sexFemale                             -0.450     0.638   0.599 6.780000e-01
race_ethnicityAll races/ethnicities    1.167     3.214   2.976 3.469000e+00
race_ethnicityAsian/PI (NH)           -2.689     0.068   0.062 7.400000e-02
race_ethnicityBlack (NH)               0.528     1.696   1.569 1.833000e+00
race_ethnicityHispanic                -1.267     0.282   0.259 3.060000e-01
race_ethnicityMultiracial (NH)        -4.989     0.007   0.006 8.000000e-03
age_category0-4                       -1.966     0.140   0.127 1.540000e-01
age_category15-24                     -1.693     0.184   0.167 2.020000e-01
age_category45-64                      1.133     3.106   2.855 3.379000e+00
age_category5-14                      -4.068     0.017   0.015 2.000000e-02
age_category65                         2.210     9.112   8.375 9.913000e+00
age_categoryAll ages                   2.646    14.099  12.966 1.532800e+01
year                                   0.001     1.001   0.963 1.041000e+00
fentanyl_surge                        -0.011     0.989   0.871 1.122000e+00
narcan_distribution                    0.029     1.029   0.898 1.179000e+00
narcan_vending_machines               -0.091     0.913   0.803 1.039000e+00
otc_narcan                            -0.174     0.840   0.744 9.490000e-01
covid_onset                            0.223     1.250   1.100 1.421000e+00
vaccine_rollout                           NA        NA      NA           NA
booster_campaigns                      0.018     1.018   0.895 1.158000e+00

Summarizing Rate Ratios from Negative Binomial Regression of Mortality Counts: This step presents the results of the Negative Binomial regression in a clean and interpretable table of rate ratios. The tidy output is reformatted to highlight each predictor, its estimated multiplicative effect on expected deaths, the 95% confidence interval bounds, and the associated p‑value. By rounding values for readability, the table makes it easy to see which predictors are statistically significant and the magnitude of their effects.

In this analysis, Male is the baseline for sex, White (NH) for race/ethnicity, and 25–44 years for age category. Demographic variables show strong and highly significant associations: females and most minority groups have lower expected deaths compared to baselines, while Black (NH) shows higher mortality. Age is a dominant factor, with older groups (45–64, 65+) associated with substantially higher deaths, the “All ages” group showing about 14 times higher deaths, and younger groups (5–24) displaying strong protective effects. The year variable is not significant once demographics are controlled.

Interventions show mixed results. OTC Narcan is associated with about 16% fewer deaths, while COVID onset corresponds to a 25% increase. Other interventions, including fentanyl surge, Narcan distribution, vending machines, and booster campaigns, are not statistically significant in this model.

Overall, the structured table of rate ratios provides a clear summary of regression findings, emphasizing the dominant role of demographics and the measurable impact of select interventions on mortality counts.

# Tidy NB regression output with exponentiation
tidy_nb <- broom::tidy(nb_model, conf.int = TRUE, exponentiate = TRUE)

# Format the table correctly
rate_ratio_table_nb <- tidy_nb %>%
  dplyr::select(term, estimate, conf.low, conf.high, p.value) %>%   # note: no commas between args
  dplyr::rename(
    Predictor = term,
    RateRatio = estimate,
    LowerCI   = conf.low,
    UpperCI   = conf.high,
    PValue    = p.value
  ) %>%
  dplyr::mutate(
    RateRatio = round(RateRatio, 3),
    LowerCI   = round(LowerCI, 3),
    UpperCI   = round(UpperCI, 3),
    PValue    = signif(PValue, 3)
  )

rate_ratio_table_nb
# A tibble: 21 × 5
   Predictor                           RateRatio LowerCI  UpperCI    PValue
   <chr>                                   <dbl>   <dbl>    <dbl>     <dbl>
 1 (Intercept)                            26.7     0     3.74e+35 9.35e-  1
 2 sexAll sexes                            1.68    1.59  1.78e+ 0 3.03e- 69
 3 sexFemale                               0.638   0.599 6.78e- 1 4.34e- 48
 4 race_ethnicityAll races/ethnicities     3.21    2.98  3.47e+ 0 9.49e-200
 5 race_ethnicityAsian/PI (NH)             0.068   0.062 7.4 e- 2 0        
 6 race_ethnicityBlack (NH)                1.70    1.57  1.83e+ 0 3.29e- 42
 7 race_ethnicityHispanic                  0.282   0.259 3.06e- 1 2.20e-211
 8 race_ethnicityMultiracial (NH)          0.007   0.006 8   e- 3 0        
 9 age_category0-4                         0.14    0.127 1.54e- 1 0        
10 age_category15-24                       0.184   0.167 2.02e- 1 1.13e-272
# ℹ 11 more rows

Visualizing Mortality Predictors with a Forest Plot: The forest plot provides a visual summary of the rate ratios from the Negative Binomial regression, showing the effects of demographics and interventions on mortality counts. Each dot represents the estimated rate ratio for a predictor, while horizontal bars display the 95% confidence intervals. The red dashed vertical line at 1 marks the null effect, meaning no change in deaths. Predictors plotted to the left of 1 are associated with fewer deaths, while those to the right are associated with more deaths. The log scale on the x‑axis allows both very large and very small effects to be compared side by side.

Model fit statistics confirm the robustness of the analysis: theta = 5.83 (SE = 0.25), residual deviance = 1,263.7 on 1,186 degrees of freedom, and AIC = 15,629, all indicating better performance than the Poisson regression. In this analysis, Male is the baseline for sex, White (NH) for race/ethnicity, and 25–44 years for age category.

The plot highlights strong protective effects for females and most minority groups compared to baselines, while Black (NH) and older age groups (45–64, 65+) show substantially higher expected deaths. The 65+ group is associated with about 9 times higher deaths, and the “All ages” group with about 14 times higher deaths relative to 25–44. Younger groups (5–24) are plotted far to the left, reflecting strong protective effects.

Among interventions, OTC Narcan is associated with a significant reduction (~16% fewer deaths), while COVID onset corresponds to a substantial increase (~25% higher deaths). Other predictors — including the year trend, fentanyl surge, Narcan distribution, vending machines, and booster campaigns — do not show statistically significant effects.

Color‑coding the predictors by group further enhances readability, making it easy to distinguish between demographics, opioid interventions, and COVID interventions. Overall, the forest plot offers an intuitive view of predictors, highlighting the dominant role of demographics and the measurable impact of select interventions, supported by strong model fit statistics.

# Start from tidy NB regression output with confidence intervals
df <- broom::tidy(nb_model, conf.int = TRUE, exponentiate = TRUE) %>%
  dplyr::select(term, estimate, conf.low, conf.high, p.value) %>%
  dplyr::rename(
    Predictor = term,
    RateRatio = estimate,
    LowerCI   = conf.low,
    UpperCI   = conf.high,
    PValue    = p.value
  )

# Remove baseline categories (they always equal 1 and add clutter)
df <- df %>%
  filter(!Predictor %in% c("sexMale", "race_ethnicityWhite (NH)", "age_category25-44"))

# Optional: relabel predictors for readability
df$Predictor <- recode(df$Predictor,
  "sexFemale" = "Female",
  "race_ethnicityAsian/PI (NH)" = "Asian/PI (NH)",
  "race_ethnicityBlack (NH)" = "Black (NH)",
  "race_ethnicityHispanic" = "Hispanic",
  "race_ethnicityMultiracial (NH)" = "Multiracial (NH)",
  "age_category5-14" = "Age 5–14",
  "age_category15-24" = "Age 15–24",
  "age_category45-64" = "Age 45–64",
  "age_category65+" = "Age 65+"
)

# Order predictors for plotting
df$Predictor <- factor(df$Predictor, levels = rev(unique(df$Predictor)))

# Forest plot
ggplot(df, aes(x = RateRatio, y = Predictor)) +
  geom_point(size = 3, color = "lightblue") +
  geom_errorbarh(aes(xmin = LowerCI, xmax = UpperCI),
                 height = 0.3, size = 1, color = "black") +
  geom_vline(xintercept = 1, linetype = "dashed", color = "red") +
  scale_x_log10() +
  coord_cartesian(xlim = c(0.001, 200)) +   # extend lower bound to show very small values
  labs(title = "Forest Plot of Predictors of Mortality",
       x = "Rate Ratio (log scale)", y = "") +
  theme_minimal(base_size = 12)
Warning: `geom_errorbarh()` was deprecated in ggplot2 4.0.0.
ℹ Please use the `orientation` argument of `geom_errorbar()` instead.
`height` was translated to `width`.

  • Note: the next sections of narrative and code were specifically formulated to address my original hypothesis that required further exploration

    Forest Plot of Intervention Effects on Mortality with negative bimodal regression: This forest plot focuses on the effects of opioid and COVID interventions on mortality. OTC Narcan shows a significant protective effect, with a rate ratio of 0.84 (95% CI: 0.74–0.95), corresponding to roughly 16% fewer deaths. In contrast, the onset of COVID is linked to a significant harmful effect, with a rate ratio of 1.25 (95% CI: 1.10–1.42), indicating about 25% more deaths. Other interventions, including the fentanyl surge, Narcan distribution, vending machines, and booster campaigns, have confidence intervals that cross 1, suggesting their effects are not statistically significant in this model.

    Overall, the forest plot provides an intervention‑focused perspective, highlighting the measurable impact of OTC Narcan and COVID onset while showing limited evidence for other policies.

# Create a data frame of intervention predictors only
df_interventions <- data.frame(
  Predictor = c("fentanyl_surge","narcan_distribution","narcan_vending",
                "otc_narcan","covid_onset","booster_campaigns"),
  RateRatio = c(0.989,1.029,0.913,0.840,1.250,1.018),
  LowerCI   = c(0.871,0.898,0.803,0.744,1.100,0.895),
  UpperCI   = c(1.122,1.179,1.039,0.949,1.421,1.158)
)

# Order predictors for plotting
df_interventions$Predictor <- factor(df_interventions$Predictor,
                                     levels = rev(df_interventions$Predictor))

# Forest plot
ggplot(df_interventions, aes(x = RateRatio, y = Predictor)) +
  geom_point(size = 3, color = "darkgreen") +
  geom_errorbarh(aes(xmin = LowerCI, xmax = UpperCI), height = 0.2) +
  geom_vline(xintercept = 1, linetype = "dashed", color = "red") +
  scale_x_log10(limits = c(0.7, 1.5)) +   # zoom in for clarity
  labs(title = "Forest Plot of Intervention Effects on Mortality",
       x = "Rate Ratio (log scale)", y = "") +
  theme_minimal(base_size = 12)
`height` was translated to `width`.

Demographic Variation in COVID‑19 Vaccination Effectiveness: The negative binomial regression with interaction terms for vaccination years 2021–2022 and demographic subgroups was designed to test the hypothesis that COVID‑19 vaccination effectiveness in reducing mortality varied by race, age, and gender. The combined 2021–2022 indicator was selected to capture the full rollout period in one variable, avoid collinearity with separate year flags, and provide a stable, interpretable measure of overall vaccine impact.

While the overall vaccination effect across 2021–2022 was not statistically significant, subgroup analyses revealed important disparities. Hispanic populations (RR ≈ 1.35, p = 0.002) and Asian/PI groups (RR ≈ 1.34, p = 0.004) showed elevated risk relative to White (NH). Black populations trended toward disparity without reaching conventional significance (RR ≈ 1.21, p = 0.055), and Multiracial groups showed borderline evidence of elevated risk (RR ≈ 1.33, p = 0.07). Age interactions did not yield significant differences, and female sex remained protective overall (RR ≈ 0.61, p < 0.001), though vaccination did not significantly alter that effect.

Taken together, these findings suggest that vaccination effectiveness was uneven across demographic subgroups, reinforcing the importance of equity‑focused approaches in evaluating vaccine impact on mortality.

# Create combined vaccination indicator (2021–2022 only)
mortality_summary <- mortality_summary %>%
  mutate(
    vax_2021_2022 = ifelse(year %in% c(2021, 2022), 1, 0)  # vaccination rollout period
  )

# Fit Negative Binomial regression with combined vaccination × demographics
nb_vax_combined <- glm.nb(
  total_deaths ~ vax_2021_2022 * sex +
                 vax_2021_2022 * race_ethnicity +
                 vax_2021_2022 * age_category +
                 covid_onset + fentanyl_surge + narcan_distribution +
                 narcan_vending_machines + otc_narcan + booster_campaigns +
                 year,
  data = mortality_summary
)

# Summarize results
summary(nb_vax_combined)

Call:
glm.nb(formula = total_deaths ~ vax_2021_2022 * sex + vax_2021_2022 * 
    race_ethnicity + vax_2021_2022 * age_category + covid_onset + 
    fentanyl_surge + narcan_distribution + narcan_vending_machines + 
    otc_narcan + booster_campaigns + year, data = mortality_summary, 
    init.theta = 5.989645505, link = log)

Coefficients: (1 not defined because of singularities)
                                                   Estimate Std. Error z value
(Intercept)                                        2.234580  39.463120   0.057
vax_2021_2022                                     -0.006615   0.130749  -0.051
sexAll sexes                                       0.525415   0.031797  16.524
sexFemale                                         -0.443517   0.033220 -13.351
race_ethnicityAll races/ethnicities                1.149992   0.041566  27.667
race_ethnicityAsian/PI (NH)                       -2.734304   0.048941 -55.869
race_ethnicityBlack (NH)                           0.505489   0.041645  12.138
race_ethnicityHispanic                            -1.316300   0.043887 -29.993
race_ethnicityMultiracial (NH)                    -5.030614   0.064171 -78.394
age_category0-4                                   -1.892064   0.052030 -36.365
age_category15-24                                 -1.690826   0.051607 -32.763
age_category45-64                                  1.160065   0.045895  25.277
age_category5-14                                  -4.081389   0.075930 -53.752
age_category65                                     2.236299   0.045290  49.377
age_categoryAll ages                               2.672850   0.045225  59.101
covid_onset                                        0.226159   0.064220   3.522
fentanyl_surge                                    -0.010276   0.063249  -0.162
narcan_distribution                                0.029038   0.068805   0.422
narcan_vending_machines                           -0.080788   0.064753  -1.248
otc_narcan                                        -0.167879   0.095523  -1.757
booster_campaigns                                        NA         NA      NA
year                                               0.001814   0.019609   0.093
vax_2021_2022:sexAll sexes                        -0.024710   0.081011  -0.305
vax_2021_2022:sexFemale                           -0.031508   0.083977  -0.375
vax_2021_2022:race_ethnicityAll races/ethnicities  0.130730   0.105829   1.235
vax_2021_2022:race_ethnicityAsian/PI (NH)          0.304267   0.124851   2.437
vax_2021_2022:race_ethnicityBlack (NH)             0.154849   0.106102   1.459
vax_2021_2022:race_ethnicityHispanic               0.316517   0.110903   2.854
vax_2021_2022:race_ethnicityMultiracial (NH)       0.274119   0.161950   1.693
vax_2021_2022:age_category0-4                     -0.542014   0.134456  -4.031
vax_2021_2022:age_category15-24                   -0.019122   0.130110  -0.147
vax_2021_2022:age_category45-64                   -0.165766   0.115707  -1.433
vax_2021_2022:age_category5-14                     0.035135   0.169863   0.207
vax_2021_2022:age_category65                      -0.169602   0.114347  -1.483
vax_2021_2022:age_categoryAll ages                -0.167737   0.113974  -1.472
                                                  Pr(>|z|)    
(Intercept)                                       0.954844    
vax_2021_2022                                     0.959650    
sexAll sexes                                       < 2e-16 ***
sexFemale                                          < 2e-16 ***
race_ethnicityAll races/ethnicities                < 2e-16 ***
race_ethnicityAsian/PI (NH)                        < 2e-16 ***
race_ethnicityBlack (NH)                           < 2e-16 ***
race_ethnicityHispanic                             < 2e-16 ***
race_ethnicityMultiracial (NH)                     < 2e-16 ***
age_category0-4                                    < 2e-16 ***
age_category15-24                                  < 2e-16 ***
age_category45-64                                  < 2e-16 ***
age_category5-14                                   < 2e-16 ***
age_category65                                     < 2e-16 ***
age_categoryAll ages                               < 2e-16 ***
covid_onset                                       0.000429 ***
fentanyl_surge                                    0.870931    
narcan_distribution                               0.672997    
narcan_vending_machines                           0.212162    
otc_narcan                                        0.078838 .  
booster_campaigns                                       NA    
year                                              0.926277    
vax_2021_2022:sexAll sexes                        0.760355    
vax_2021_2022:sexFemale                           0.707513    
vax_2021_2022:race_ethnicityAll races/ethnicities 0.216722    
vax_2021_2022:race_ethnicityAsian/PI (NH)         0.014808 *  
vax_2021_2022:race_ethnicityBlack (NH)            0.144445    
vax_2021_2022:race_ethnicityHispanic              0.004317 ** 
vax_2021_2022:race_ethnicityMultiracial (NH)      0.090529 .  
vax_2021_2022:age_category0-4                     5.55e-05 ***
vax_2021_2022:age_category15-24                   0.883159    
vax_2021_2022:age_category45-64                   0.151963    
vax_2021_2022:age_category5-14                    0.836133    
vax_2021_2022:age_category65                      0.138017    
vax_2021_2022:age_categoryAll ages                0.141098    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for Negative Binomial(5.9896) family taken to be 1)

    Null deviance: 27219.9  on 1206  degrees of freedom
Residual deviance:  1264.1  on 1173  degrees of freedom
AIC: 15624

Number of Fisher Scoring iterations: 1

              Theta:  5.990 
          Std. Err.:  0.259 

 2 x log-likelihood:  -15553.725 
# Extract tidy coefficients with exponentiated values (rate ratios)
vax_combined_results <- tidy(nb_vax_combined, exponentiate = TRUE, conf.int = TRUE)

# Filter to vaccination-related terms (combined 2021–2022 only)
vax_combined_effects <- vax_combined_results %>%
  filter(grepl("vax_2021_2022", term)) %>%
  mutate(
    label = case_when(
      term == "vax_2021_2022" ~ "Vaccination Era (2021–2022, Overall)",
      grepl("sexFemale", term) ~ "Female, Vaccination Era",
      grepl("sexAll sexes", term) ~ "All Sexes, Vaccination Era",
      grepl("race_ethnicityBlack", term) ~ "Black (NH), Vaccination Era",
      grepl("race_ethnicityAsian/PI", term) ~ "Asian/PI (NH), Vaccination Era",
      grepl("race_ethnicityHispanic", term) ~ "Hispanic, Vaccination Era",
      grepl("race_ethnicityMultiracial", term) ~ "Multiracial (NH), Vaccination Era",
      grepl("age_category15-24", term) ~ "Age 15–24, Vaccination Era",
      grepl("age_category45-64", term) ~ "Age 45–64, Vaccination Era",
      grepl("age_category65", term) ~ "Age 65+, Vaccination Era",
      grepl("age_category5-14", term) ~ "Age 5–14, Vaccination Era",
      grepl("age_categoryAll ages", term) ~ "All Ages, Vaccination Era",
      TRUE ~ term
    )
  )

# Forest plot with clean labels
ggplot(vax_combined_effects, aes(x = estimate, y = label)) +
  geom_point(color = "blue", size = 3) +
  geom_errorbarh(aes(xmin = conf.low, xmax = conf.high), height = 0.2) +
  geom_vline(xintercept = 1, linetype = "dashed", color = "red") +
  scale_x_log10() +
  labs(title = "Vaccination Effectiveness by Demographics)",
       x = "Rate Ratio (log scale)",
       y = "Demographic Subgroup") +
  theme_minimal()
`height` was translated to `width`.

Equity Impacts of COVID Vaccination and Opioid Interventions on Mortality Disparities: This analysis tested whether disparities narrowed after interventions, specifically COVID‑19 vaccination in 2021–2022 and opioid interventions in 2017–2022, across sex, age, and race/ethnicity subgroups. A negative binomial regression was fit using the mortality_summary dataset (excluding ages 0–4), with binary indicators for vaccination and opioid interventions interacted with demographic categories. Standard baselines were applied (Male, White [NH], ages 25–44), and covariates such as fentanyl surge, COVID onset, and year were included to account for contextual mortality trends.

Results showed that vaccination had no significant overall impact, while opioid interventions were linked to a modest increase in mortality. Sex interactions revealed no evidence of narrowing or widening disparities. Race and ethnicity interactions highlighted uneven vaccination effects, with Asian/PI, Hispanic, and Multiracial groups showing weaker protective benefits compared to White (NH). For opioid interventions, Multiracial groups showed evidence of narrowed disparities, while younger (15–24) and older (45–64, 65+) age groups suggested borderline narrowing. Contextual covariates behaved as expected, with COVID onset increasing mortality, year trends showing gradual declines, and sex and race main effects confirming known disparities such as female protection, Black excess mortality, and protective effects for Asian/PI and Hispanic populations.

Overall, the hypothesis that disparities narrowed after interventions is only partially supported. Vaccination impacts varied across race and ethnicity but did not narrow disparities by sex or age, while opioid interventions provided some evidence of narrowing among Multiracial and certain age groups. These findings underscore that intervention impacts were uneven across demographic groups, with the strongest equity signals emerging in race and ethnicity interactions. Future work should refine subgroup interaction models to better quantify equity impacts and identify where interventions most effectively reduce disparities.

# Prepare dataset, join contextual variables, convert factors, create indicators
mortality_summary <- mortality_summary %>%
  # Keep only core demographic + death count columns
  dplyr::select(year, sex, race_ethnicity, age_category, total_deaths) %>%
  
  # Join contextual variables from mortality_full
  left_join(
    mortality_full %>%
      dplyr::select(year, opioid_notes, covid_vaccine_doses_philadelphia, vax_notes) %>%
      group_by(year) %>%
      summarise(
        opioid_notes = first(opioid_notes),
        covid_vaccine_doses_philadelphia = first(covid_vaccine_doses_philadelphia),
        vax_notes = first(vax_notes),
        .groups = "drop"
      ),
    by = "year"
  ) %>%
  
  # Convert categorical variables to factors
  mutate(
    sex = factor(sex),
    race_ethnicity = factor(race_ethnicity),
    age_category = factor(age_category)
  ) %>%
  
  # Exclude age group 0–4
  filter(age_category != "0-4") %>%
  
  # Create binary indicators for interventions
  mutate(
    fentanyl_surge       = ifelse(year >= 2014, 1, 0),
    opioid_any           = ifelse(year %in% 2017:2022, 1, 0),
    covid_onset          = ifelse(year >= 2020, 1, 0),
    vax_any              = ifelse(year %in% c(2021, 2022), 1, 0),
    vaccine_rollout      = ifelse(!is.na(covid_vaccine_doses_philadelphia), 1, 0),
    booster_campaigns    = ifelse(year >= 2021, 1, 0)
  )

# Set baselines for categorical predictors
mortality_summary$sex <- relevel(mortality_summary$sex, ref = "Male")
mortality_summary$race_ethnicity <- relevel(mortality_summary$race_ethnicity, ref = "White (NH)")
mortality_summary$age_category <- relevel(mortality_summary$age_category, ref = "25-44")

# Fit equity-focused Negative Binomial regression (your specified model)
nb_equity <- glm.nb(
  total_deaths ~ 
    vax_any * sex + vax_any * race_ethnicity + vax_any * age_category +
    opioid_any * sex + opioid_any * race_ethnicity + opioid_any * age_category +
    fentanyl_surge + covid_onset + year,
  data = mortality_summary
)

# Summarize results
summary(nb_equity)

Call:
glm.nb(formula = total_deaths ~ vax_any * sex + vax_any * race_ethnicity + 
    vax_any * age_category + opioid_any * sex + opioid_any * 
    race_ethnicity + opioid_any * age_category + fentanyl_surge + 
    covid_onset + year, data = mortality_summary, init.theta = 6.82008374, 
    link = log)

Coefficients:
                                                Estimate Std. Error z value
(Intercept)                                    51.595389  17.648525   2.923
vax_any                                        -0.140941   0.131396  -1.073
sexAll sexes                                    0.505110   0.039946  12.645
sexFemale                                      -0.490706   0.041470 -11.833
race_ethnicityAll races/ethnicities             1.021718   0.052953  19.295
race_ethnicityAsian/PI (NH)                    -2.851322   0.059046 -48.290
race_ethnicityBlack (NH)                        0.335240   0.053040   6.321
race_ethnicityHispanic                         -1.542299   0.055295 -27.892
race_ethnicityMultiracial (NH)                 -5.030147   0.076225 -65.991
age_category15-24                              -1.608617   0.060924 -26.404
age_category45-64                               1.216017   0.054148  22.457
age_category5-14                               -4.043516   0.092516 -43.706
age_category65                                  2.282653   0.053502  42.664
age_categoryAll ages                            2.720997   0.053423  50.933
opioid_any                                      0.237414   0.094922   2.501
fentanyl_surge                                  0.068574   0.049362   1.389
covid_onset                                     0.306350   0.061357   4.993
year                                           -0.022691   0.008769  -2.588
vax_any:sexAll sexes                           -0.003178   0.090391  -0.035
vax_any:sexFemale                              -0.032958   0.093949  -0.351
vax_any:race_ethnicityAll races/ethnicities     0.136291   0.119889   1.137
vax_any:race_ethnicityAsian/PI (NH)             0.327876   0.134835   2.432
vax_any:race_ethnicityBlack (NH)                0.163690   0.120126   1.363
vax_any:race_ethnicityHispanic                  0.266099   0.124766   2.133
vax_any:race_ethnicityMultiracial (NH)          0.522454   0.176104   2.967
vax_any:age_category15-24                       0.092621   0.138291   0.670
vax_any:age_category45-64                      -0.077626   0.122711  -0.633
vax_any:age_category5-14                        0.063511   0.185797   0.342
vax_any:age_category65                         -0.075839   0.121103  -0.626
vax_any:age_categoryAll ages                   -0.084079   0.120731  -0.696
sexAll sexes:opioid_any                        -0.005336   0.066084  -0.081
sexFemale:opioid_any                            0.010686   0.068746   0.155
race_ethnicityAll races/ethnicities:opioid_any  0.033314   0.087614   0.380
race_ethnicityAsian/PI (NH):opioid_any          0.022063   0.098085   0.225
race_ethnicityBlack (NH):opioid_any             0.067504   0.087747   0.769
race_ethnicityHispanic:opioid_any               0.137590   0.091480   1.504
race_ethnicityMultiracial (NH):opioid_any      -0.309995   0.129416  -2.395
age_category15-24:opioid_any                   -0.185394   0.101059  -1.835
age_category45-64:opioid_any                   -0.151289   0.089626  -1.688
age_category5-14:opioid_any                    -0.065245   0.148892  -0.438
age_category65:opioid_any                      -0.152758   0.088336  -1.729
age_categoryAll ages:opioid_any                -0.141521   0.088204  -1.604
                                               Pr(>|z|)    
(Intercept)                                     0.00346 ** 
vax_any                                         0.28343    
sexAll sexes                                    < 2e-16 ***
sexFemale                                       < 2e-16 ***
race_ethnicityAll races/ethnicities             < 2e-16 ***
race_ethnicityAsian/PI (NH)                     < 2e-16 ***
race_ethnicityBlack (NH)                       2.61e-10 ***
race_ethnicityHispanic                          < 2e-16 ***
race_ethnicityMultiracial (NH)                  < 2e-16 ***
age_category15-24                               < 2e-16 ***
age_category45-64                               < 2e-16 ***
age_category5-14                                < 2e-16 ***
age_category65                                  < 2e-16 ***
age_categoryAll ages                            < 2e-16 ***
opioid_any                                      0.01238 *  
fentanyl_surge                                  0.16477    
covid_onset                                    5.95e-07 ***
year                                            0.00967 ** 
vax_any:sexAll sexes                            0.97195    
vax_any:sexFemale                               0.72573    
vax_any:race_ethnicityAll races/ethnicities     0.25562    
vax_any:race_ethnicityAsian/PI (NH)             0.01503 *  
vax_any:race_ethnicityBlack (NH)                0.17299    
vax_any:race_ethnicityHispanic                  0.03294 *  
vax_any:race_ethnicityMultiracial (NH)          0.00301 ** 
vax_any:age_category15-24                       0.50301    
vax_any:age_category45-64                       0.52700    
vax_any:age_category5-14                        0.73248    
vax_any:age_category65                          0.53116    
vax_any:age_categoryAll ages                    0.48617    
sexAll sexes:opioid_any                         0.93564    
sexFemale:opioid_any                            0.87647    
race_ethnicityAll races/ethnicities:opioid_any  0.70377    
race_ethnicityAsian/PI (NH):opioid_any          0.82202    
race_ethnicityBlack (NH):opioid_any             0.44171    
race_ethnicityHispanic:opioid_any               0.13257    
race_ethnicityMultiracial (NH):opioid_any       0.01660 *  
age_category15-24:opioid_any                    0.06658 .  
age_category45-64:opioid_any                    0.09141 .  
age_category5-14:opioid_any                     0.66124    
age_category65:opioid_any                       0.08376 .  
age_categoryAll ages:opioid_any                 0.10861    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for Negative Binomial(6.8201) family taken to be 1)

    Null deviance: 25705.6  on 1065  degrees of freedom
Residual deviance:  1115.2  on 1024  degrees of freedom
AIC: 14178

Number of Fisher Scoring iterations: 1

              Theta:  6.820 
          Std. Err.:  0.315 

 2 x log-likelihood:  -14092.208 
# Extract tidy results for equity-focused forest plot
equity_results <- tidy(nb_equity, exponentiate = TRUE, conf.int = TRUE)

equity_effects <- equity_results %>%
  filter(grepl("vax_any|opioid_any", term))

# Forest plot of subgroup-specific intervention effects
ggplot(equity_effects, aes(x = estimate, y = term)) +
  geom_point(color = "blue", size = 3) +
  geom_errorbarh(aes(xmin = conf.low, xmax = conf.high), height = 0.2) +
  geom_vline(xintercept = 1, linetype = "dashed", color = "red") +
  scale_x_log10() +
  labs(title = "Equity-Focused Intervention Effects (Sex, Age, Race)",
       x = "Rate Ratio (log scale)",
       y = "Intervention × Subgroup") +
  theme_minimal()
`height` was translated to `width`.

Evaluating Age‑Specific Impacts of Narcan Interventions (2017–2022): To test the hypothesis that Narcan’s impact on reducing mortality is greater in younger groups, a negative binomial regression was fit using the mortality_summary dataset. Binary indicators were created for Narcan interventions in 2017, 2022, and a combined 2017–2022 measure (narcan_any), which was interacted with age categories (baseline: 25–44). Standard demographic and contextual covariates were included, with predictors re‑leveled to set meaningful baselines.

Results show that the baseline group (ages 25–44) had a significant positive Narcan effect (Estimate = 0.33, p < 0.001). Older groups (45–64, 65+) experienced significantly weaker impacts (Estimates = –0.20, p = 0.026; –0.23, p = 0.009), and the “All ages” aggregate also showed a weaker effect (Estimate = –0.22, p = 0.012). Younger groups (15–24, 5–14) did not differ significantly from the baseline, indicating similar rather than stronger effects. Year‑specific indicators for 2017 and 2022 showed no significant main effects, suggesting the combined measure captured the consistent pattern. Other covariates behaved as expected: COVID onset increased mortality (Estimate = 0.30, p < 0.001), females were protective relative to males, and Black populations experienced excess mortality.

In summary, Narcan’s impact was strongest among adults aged 25–44, weaker in older groups, and similar in younger groups, providing no support for the hypothesis that younger populations benefited more. These findings highlight that Narcan interventions reduced mortality most clearly in the 25–44 age group and underscore the need for further subgroup‑focused evaluation to understand age‑specific dynamics.

# Exclude age group 0–4
mortality_summary <- mortality_summary %>%
  filter(age_category != "0-4") %>%   # remove 0–4 from analysis
  mutate(
    narcan_2017 = ifelse(year == 2017, 1, 0),
    narcan_2022 = ifelse(year == 2022, 1, 0),
    narcan_any  = ifelse(year %in% 2017:2022, 1, 0)  # combined indicator for all years 2017–2022
  )

# Fit Negative Binomial regression with Narcan years × age categories
nb_narcan_years <- glm.nb(
  total_deaths ~ narcan_any * age_category +
                 narcan_2017 * age_category +
                 narcan_2022 * age_category +
                 sex + race_ethnicity +
                 fentanyl_surge + covid_onset +
                 vaccine_rollout + booster_campaigns +
                 year,
  data = mortality_summary
)

# Summarize results
summary(nb_narcan_years)

Call:
glm.nb(formula = total_deaths ~ narcan_any * age_category + narcan_2017 * 
    age_category + narcan_2022 * age_category + sex + race_ethnicity + 
    fentanyl_surge + covid_onset + vaccine_rollout + booster_campaigns + 
    year, data = mortality_summary, init.theta = 6.664874574, 
    link = log)

Coefficients: (1 not defined because of singularities)
                                    Estimate Std. Error z value Pr(>|z|)    
(Intercept)                         55.18240   20.30322   2.718  0.00657 ** 
narcan_any                           0.33327    0.06822   4.885 1.03e-06 ***
age_category15-24                   -1.60833    0.06135 -26.214  < 2e-16 ***
age_category45-64                    1.22820    0.05469  22.459  < 2e-16 ***
age_category5-14                    -4.02852    0.09201 -43.785  < 2e-16 ***
age_category65                       2.30888    0.05378  42.931  < 2e-16 ***
age_categoryAll ages                 2.74692    0.05356  51.289  < 2e-16 ***
narcan_2017                         -0.06724    0.11883  -0.566  0.57152    
narcan_2022                         -0.05075    0.12077  -0.420  0.67430    
sexAll sexes                         0.50143    0.02952  16.987  < 2e-16 ***
sexFemale                           -0.49115    0.03067 -16.012  < 2e-16 ***
race_ethnicityAll races/ethnicities  1.05556    0.03916  26.957  < 2e-16 ***
race_ethnicityAsian/PI (NH)         -2.79057    0.04379 -63.719  < 2e-16 ***
race_ethnicityBlack (NH)             0.38957    0.03922   9.933  < 2e-16 ***
race_ethnicityHispanic              -1.43636    0.04085 -35.161  < 2e-16 ***
race_ethnicityMultiracial (NH)      -5.08691    0.05704 -89.186  < 2e-16 ***
fentanyl_surge                       0.06833    0.05190   1.317  0.18795    
covid_onset                          0.30453    0.05945   5.123 3.01e-07 ***
vaccine_rollout                           NA         NA      NA       NA    
booster_campaigns                    0.01374    0.06546   0.210  0.83378    
year                                -0.02450    0.01009  -2.428  0.01517 *  
narcan_any:age_category15-24        -0.15896    0.10075  -1.578  0.11462    
narcan_any:age_category45-64        -0.19983    0.08991  -2.223  0.02624 *  
narcan_any:age_category5-14         -0.08445    0.14387  -0.587  0.55718    
narcan_any:age_category65           -0.22904    0.08777  -2.609  0.00907 ** 
narcan_any:age_categoryAll ages     -0.21786    0.08710  -2.501  0.01237 *  
age_category15-24:narcan_2017       -0.08016    0.18082  -0.443  0.65754    
age_category45-64:narcan_2017        0.05335    0.16154   0.330  0.74122    
age_category5-14:narcan_2017         0.02167    0.24507   0.088  0.92955    
age_category65:narcan_2017           0.02239    0.15748   0.142  0.88695    
age_categoryAll ages:narcan_2017     0.05203    0.15680   0.332  0.74004    
age_category15-24:narcan_2022        0.14899    0.18006   0.827  0.40798    
age_category45-64:narcan_2022       -0.03499    0.16256  -0.215  0.82956    
age_category5-14:narcan_2022         0.08005    0.22974   0.348  0.72750    
age_category65:narcan_2022          -0.02680    0.15968  -0.168  0.86672    
age_categoryAll ages:narcan_2022    -0.07651    0.15646  -0.489  0.62486    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for Negative Binomial(6.6649) family taken to be 1)

    Null deviance: 25133.1  on 1065  degrees of freedom
Residual deviance:  1114.2  on 1031  degrees of freedom
AIC: 14187

Number of Fisher Scoring iterations: 1

              Theta:  6.665 
          Std. Err.:  0.307 

 2 x log-likelihood:  -14114.580 
# Extract tidy coefficients with exponentiated values (rate ratios)
narcan_year_results <- tidy(nb_narcan_years, exponentiate = TRUE, conf.int = TRUE)

# Filter to Narcan-related terms (main effects + interactions)
narcan_year_effects <- narcan_year_results %>%
  filter(grepl("narcan_", term))

# Forest plot of ALL subgroup-specific Narcan effects (2017–2022, excluding 0–4)
ggplot(narcan_year_effects, aes(x = estimate, y = term)) +
  geom_point(color = "purple", size = 3) +
  geom_errorbarh(aes(xmin = conf.low, xmax = conf.high), height = 0.2) +
  geom_vline(xintercept = 1, linetype = "dashed", color = "red") +
  scale_x_log10() +
  labs(title = "Narcan Effects by Age Groups (Excluding 0–4)",
       x = "Rate Ratio (log scale)",
       y = "Predictor (Interaction Term)") +
  theme_minimal()
`height` was translated to `width`.

Summary of Statistical Methods and Key Findings on Mortality Disparities in negative bimodal regression: The statistical methods section began with careful data preparation, merging mortality counts with contextual variables such as opioid interventions, COVID milestones, and vaccination data. Categorical predictors were re‑leveled to set meaningful baselines (Male, White [NH], ages 25–44), and binary indicators were created for key interventions including the fentanyl surge, Narcan distribution, vending machines, OTC Narcan, COVID onset, vaccination rollout, and booster campaigns. Exploratory linear regression provided an initial view of associations but showed limitations for count data, with demographics driving most of the variation and interventions not significant. Poisson regression improved interpretability by converting coefficients to rate ratios, confirming that demographics were dominant predictors while interventions showed measurable but smaller effects (e.g., OTC Narcan protective, COVID onset harmful). Negative binomial regression addressed overdispersion and yielded stronger model fit, again confirming the dominant role of demographics while highlighting significant effects for OTC Narcan and COVID onset. Interaction models were then used to explore subgroup variation in intervention impacts, testing equity effects of vaccination (2021–2022) and opioid interventions (2017–2022) across sex, race/ethnicity, and age. Additional models examined age‑specific impacts of Narcan interventions, while forest plots provided intuitive visualizations of both demographic and intervention predictors.

Significant findings emerged across multiple dimensions. Females consistently showed fewer deaths relative to males, while race and ethnicity disparities were clear: Black (NH) populations had higher mortality, whereas Asian/PI, Hispanic, and Multiracial groups showed protective effects. Age was the strongest predictor, with those aged 65+ and the “All ages” group showing about 9× and 14× higher deaths compared to 25–44, while younger groups showed protective effects. Among interventions, OTC Narcan significantly reduced mortality (~16%), and COVID onset significantly increased mortality (~25%). Other opioid interventions and COVID booster campaigns were not significant. Equity analyses revealed that vaccination effectiveness varied by race and ethnicity, with weaker protective effects for Hispanic, Asian/PI, and Multiracial groups, while opioid interventions narrowed disparities for Multiracial groups and showed borderline narrowing for younger and older age categories. Sex disparities remained unchanged across interventions. Age‑specific Narcan effects showed the strongest impact in the 25–44 group, weaker effects in older groups, and similar effects in younger groups, thereby not supporting the hypothesis that Narcan is more protective for youth.

5 Hypothesis Testing and Evaluation of Findings

5.2 Intervention Impact Hypotheses

  • COVID‑19 mortality declined following vaccination rollout (late 2020 onward): ✖ Not supported

    • Vaccination indicators were not significant overall; subgroup analyses revealed uneven or weaker protective effects.
  • Opioid mortality declined after Narcan distribution to first responders (2017): ✖ Not supported

    • Narcan distribution showed no significant protective effect in the models.
  • Free Narcan vending machines (2022) reduced overdose deaths: ✖ Not supported

    • Vending machines showed borderline reductions but were not statistically significant.
  • Over‑the‑counter Narcan (2023) contributed to declines across demographic groups: ✔ Supported

    • OTC Narcan was consistently protective, associated with ~16% fewer deaths.

5.3 Interaction Hypotheses

  • Effectiveness of vaccination varied by race, age, and gender: ✔ Supported

    • Subgroup analyses showed weaker protective effects (or elevated risk) for Hispanic, Asian/PI, and Multiracial groups.

    • Female sex remained protective but unaffected by vaccination.

  • Narcan’s impact was greater in younger age groups: ✖ Not supported

    • The strongest Narcan effect was in the 25–44 baseline group.

    • Younger groups showed similar but not stronger effects.

    • Older groups showed weaker impacts.

  • Mortality disparities narrowed following interventions, suggesting improved equity: ✖ Partially supported

    • Opioid interventions narrowed disparities for Multiracial groups.

    • Borderline narrowing appeared for younger and older age categories.

    • Vaccination did not clearly narrow disparities.

    • Sex disparities remained unchanged.

5.4 Overall Assessment

Strongly supported hypotheses included: COVID onset increased mortality; fentanyl surge increased opioid deaths; older age groups disproportionately affected; males disproportionately affected; OTC Narcan protective; and vaccination effectiveness varied by race/ethnicity. Partially supported hypotheses included Black and Hispanic excess mortality (only Black consistently elevated) and equity narrowing (only Multiracial and some age groups showed signals). Not supported hypotheses included vaccination reducing mortality overall, Narcan distribution and vending machines reducing deaths, and Narcan being more protective in youth.

These evaluations integrate both regression models and interrupted time series analyses, ensuring that temporal disruptions such as COVID onset and fentanyl emergence are fully represented alongside subgroup and intervention effects.

6 Conclusion

This study examined mortality trends in Philadelphia across sex, race/ethnicity, and age categories in the context of opioid and COVID‑19 interventions, using a revised interrupted time series (ITS) framework and regression modeling. Visualizations revealed sharp increases in deaths following the 2014 fentanyl surge and the 2020 onset of COVID, with persistent disparities across demographic groups. Vaccination rollout did not produce uniform protective effects, instead showing uneven impacts across racial and ethnic subgroups. Opioid interventions, including Narcan distribution, vending machines, and OTC availability, produced mixed results, with OTC Narcan emerging as the most consistent protective measure.

Regression analyses confirmed that demographics are the dominant drivers of mortality variation. Females consistently experienced fewer deaths than males, Asian/PI and Hispanic groups showed protective effects relative to White (NH), while Black populations faced excess mortality. Age was the strongest predictor, with older groups experiencing dramatically higher death counts. Linear and Poisson regression were explored, but negative binomial regression provided the best fit and inference. By accounting for overdispersion, it yielded stronger model performance, more reliable estimates, and confirmed significant effects for OTC Narcan (protective) and COVID onset (harmful). Forest plots visually reinforced these findings, showing that demographic predictors far outweighed interventions in their impact.

Hypothesis testing further clarified the strength of these results. Mortality trend hypotheses were strongly supported, with crises such as the fentanyl surge and COVID onset producing sharp increases, older age groups and males disproportionately affected, and Black populations consistently showing excess mortality, though Hispanic groups demonstrated protective effects rather than excess risk. Intervention impact hypotheses were only partially supported: OTC Narcan significantly reduced mortality, but Narcan distribution, vending machines, and vaccination rollout did not show consistent protective effects. Interaction hypotheses were mixed—vaccination effectiveness varied across race and ethnicity, confirming inequities, but did not narrow disparities by sex or age. Narcan’s impact was strongest in the 25–44 group rather than in youth, and opioid interventions narrowed disparities for Multiracial groups with borderline narrowing for younger and older age categories. Taken together, the hypothesis testing framework demonstrated that while some expectations were confirmed, others were only partially supported or contradicted, underscoring the complexity of intervention impacts across demographic subgroups.

These findings underscore three central points: first, demographic disparities drive mortality patterns more than interventions, with race/ethnicity and age showing the most pronounced inequities. Second, intervention impacts are uneven, with OTC Narcan emerging as the clearest protective measure, while vaccination and other opioid interventions showed subgroup differences that limited equity gains. Third, the negative binomial regression model was the most appropriate analytic approach—ITS and exploratory models provided context, but only the negative binomial regression produced robust, interpretable results for Philadelphia mortality data. Together, ITS and regression analyses provided complementary perspectives, ensuring that both temporal disruptions and subgroup disparities were fully captured. Future work should refine subgroup interaction models and expand equity‑focused evaluation to identify where interventions most effectively reduce disparities. Public health strategies must be tailored to demographic realities, ensuring that policies not only reduce overall mortality but also close gaps across sex, race/ethnicity, and age.